class Solution {
public:
    void reserve(vector<int>& nums, int left, int right) {
        while (left < right) {
            swap(nums[left], nums[right]);
            left++;
            right--;
        }
    }
    void rotate(vector<int>& nums, int k) {
        int sz = nums.size();
        k %= sz;
        if (k == 0)
            return;
        reserve(nums, 0, sz - k - 1);
        reserve(nums, sz - k, sz - 1);
        reserve(nums, 0, sz - 1);
    }
};